package com.atguigu.gmall.item.rpc;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.item.service.SkuDetailItemService;
import com.atguigu.gmall.model.to.SkuDetailTo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2025/8/29 20:34
 */
@RestController
@RequestMapping("/rpc/inner/item")
public class SkuDetailItemController {
    @Autowired
    private SkuDetailItemService skuDetailItemService;
    @Autowired
    private ThreadPoolExecutor coreThreadPool;
    @GetMapping("/getSkuDetail")
    public Result<SkuDetailTo> getSkuDetail(@RequestParam("skuId") Long skuId){
        SkuDetailTo skuDetailTo =skuDetailItemService.getSkuDetail(skuId);
        coreThreadPool.execute(()->{
            skuDetailItemService.updateScoreASync(skuId);
        });
        return Result.ok(skuDetailTo);
    }
}
